#ifndef FXPKI_H
#define FXPKI_H

/** 
 * Initial the PKI module.
 */
void FXPKI_Init();

/** 
 * Finalize the PKI module.
 */
void FXPKI_Finalize();
	
/** 
 * Create RSA private and public key.
 *
 * @param[in]	nBits			The length of the key(eg.1024, 2048...)
 * @param[in]	bsSeed			A seed, which is a string for generating keys
 * @param[in]	bsPassword		The password used to encrypt private key.(now not support)
 * @param[out]	bsPubKey		A public key
 * @param[out]	bsPrvKey		A private key
 */
void FXPKI_CreateRsaKey(FX_INT32 nBits, 
						FX_BSTR bsSeed,
						FX_BSTR bsPassword, 
						CFX_ByteString &bsPubKey,
						CFX_ByteString &bsPrvKey);

/** 
 * Encrypt data used by RSA public key.
 *
 * @param[in]	bsData			The data which needs to be encrypted, the data length must be bigger than 4 bytes, otherwise, can't be decrypted
 * @param[in]	bsPubKey		The public key for encrypting
 * @param[out]	bsEncryptedData Result
 */
void FXPKI_RsaEncrypt(	FX_BSTR bsData,
						FX_BSTR bsPubKey,
						CFX_ByteString &bsEncryptedData);

/** 
* Decrypt data used by RSA private key.
*
* @param[in]	bsData			The data which needs to be decrypted
* @param[in]	bsPrvKey		The private key for decrypting
* @param[out]	bsDecryptedData Result
*/
void FXPKI_RsaDecrypt(	FX_BSTR bsData,
						FX_BSTR bsPrvKey,
						CFX_ByteString &bsDecryptedData);

/** 
 * Signature data used by RSA private key.
 *
 * @param[in]	bsData			The data which needs to be signed
 * @param[in]	bsPrvKey		The private key for signing
 * @param[out]	bsSign			Result
 */
void FXPKI_RsaSign(FX_BSTR bsData,
				   FX_BSTR bsPrvKey,
				   CFX_ByteString &bsSign);

/** 
 * Verify the signature used by RSA public key.
 *
 * @param[in]	bsData			The data which has been signed
 * @param[in]	bsSign			The signature
 * @param[in]	bsPubKey		The public key for checking signature
 * return the result of verify. (FALSE fail else success).
 */
FX_BOOL FXPKI_VerifyRsaSign(FX_BSTR bsData,
							FX_BSTR bsSign,
							FX_BSTR bsPubKey);


/** 
 * Create DSA private and public key (key bit size is 1024).
 *
 * @param[in]	bsSeed			A seed
 * @param[in]	bsPassword		The password used to encrypt private key.(now not support)
 * @param[out]	bsPublicKey		A public key
 * @param[out]	bsPrivateKey	A private key
 */
void FXPKI_CreateDsaKey(FX_BSTR bsSeed,
						FX_BSTR bsPassword, 
						CFX_ByteString &bsPubKey,
						CFX_ByteString &bsPrvKey);

/** 
 * Signature data used by DSA private key.
 *
 * @param[in]	bsData			The primitive data.
 * @param[in]	bsPrvKey		The private key.
 * @param[out]	bsSign			A signature
 */
void FXPKI_DsaSign(FX_BSTR bsData,
				   FX_BSTR bsPrvKey,
				   CFX_ByteString &bsSign);

/** 
 * Verify the signature used by DSA public key.
 *
 * @param[in]	bsData			The primitive data.
 * @param[in]	bsSign			The signature value.
 * @param[in]	bsPubKey		The public key.
 * return the result of verify. (FALSE fail else success).
 */
FX_BOOL FXPKI_VerifyDsaSign(FX_BSTR bsData,
							FX_BSTR bsSign,
							FX_BSTR bsPubKey);


/** 
 * Verify RSA key validity.
 *
 * @param[in]	bsKey			RSA key.
 * @param[in]	nBits			define RSA key length
 * @param[in]	bIsPubKey		The bsKey is public key if this parameter is true, otherwise bsKey is Private Key.
 * @param[out]	nRet			result code;
 * 0:	success
 * 1:	Incorrect key length
 * 2:	Key parameter is not compatible with nBits
 * 3:	Key parameter is not odd 
 * 4:   Private key parameters relationship broken
 * return :		the result of verify. (return true success, otherwise failed).
 */
FX_BOOL FXPKI_VerifyRsaKey(FX_BSTR bsKey, 
							FX_INT32 nBits,
						    FX_BOOL bIsPubKey,
							FX_INT32 &nRet);


/** (Hasn't been implemented yet!!!)
 * Verify DSA key validity.
 *
 * @param[in]	bsKey			DSA key.
 * @param[in]	nBits			define DSA key length
 * @param[in]	bIsPubKey		The bsKey is public key if this parameter is true, otherwise bsKey is Private Key.
 * @param[out]	nRet			result code;
 * return the result of verify. (return true success, otherwise failed).
 */
FX_BOOL FXPKI_VerifyDasKey(FX_BSTR bsKey, 
						   FX_INT32 nBits,
						   FX_BOOL bIsPubKey,
						   FX_INT32 &nRet);

#endif
